Writing a Complete List of Device Drivers to a Text File
There are times when you
wish you had a list of all the drivers installed on your PC. For
example, if your system crashes, it would be nice to have some kind of
record of what drivers are in there. More likely, such a list would come
in handy if you have to set up your PC from scratch and you want to
know which drivers you have to update.
How do you get such a
list? Oddly, Windows doesn’t give you any straightforward way to do
this. However, you can make your own list by using a script like the one
shown in Listing 1.
Listing 1. Script That Writes a Complete List of a PC’s Installed Device Drivers to a Text File
Dim strComputer, objWMI, collDrivers, objDriver, intDrivers Dim objFSO, strFolder, objFile ' ' Change the following value to the path of the folder ' where you want to store the text file ' strFolder = "d:\backups\" ' ' Initialize the file system object ' Set objFSO = CreateObject("Scripting.FileSystemObject") ' ' Create the text file ' Set objFile = objFSO.CreateTextFile(strFolder & "drivers.txt", True) ' ' Get the WMI object ' strComputer = "." Set objWMI = GetObject("winmgmts:\\" & strComputer) ' ' Return the collection of device drivers on the computer ' Set collDrivers = objWMI.ExecQuery _ ("Select * from Win32_PnPSignedDriver") ' ' Run through each item in the collection ' intDrivers = 0 For Each objDriver in collDrivers ' ' Write the driver data to the text file ' objFile.WriteLine(objDriver.DeviceName) objFile.WriteLine("========================================") objFile.WriteLine("Device Class: " & objDriver.DeviceClass) objFile.WriteLine("Device Description: " & objDriver.Description) objFile.WriteLine("Device ID: " & objDriver.DeviceID) objFile.WriteLine("INF Filename: " & objDriver.InfName) objFile.WriteLine("Driver Provider: " & objDriver.DriverProviderName) objFile.WriteLine("Driver Version: " & objDriver.DriverVersion) objFile.WriteLine("Driver Date: " & ReturnDriverDate(objDriver.DriverDate)) objFile.WriteLine("") intDrivers = intDrivers + 1 Next ' ' Close the text file ' objFile.Close WScript.Echo "Wrote " & intDrivers & " drivers to the text file."
' ' ReturnDriverDate() ' This function takes the driver datetime value and converts ' it to a friendlier date and time format '
Function ReturnDriverDate(dDriverDate) Dim eventDay, eventMonth, eventYear Dim eventSecond, eventMinute, eventHour eventYear = Left(dDriverDate, 4) eventMonth = Mid(dDriverDate, 5, 2) eventDay = Mid(dDriverDate, 7, 2) eventHour = Mid(dDriverDate, 9, 2) eventMinute = Mid(dDriverDate, 11, 2) eventSecond = Mid(dDriverDate, 13, 2) ReturnDriverDate = DateSerial(eventYear, eventMonth, eventDay) & _ " " & TimeSerial(eventHour, eventMinute, eventSecond) End Function
|
The script uses VBScript’s FileSystemObject to connect to the PC’s file system. In this case, the script uses FileSystemObject to create a new text file in the folder specified by strFolder.
The script then sets up the usual Windows Management Instrumentation
(WMI) object, and then uses WMI to return the collection of installed
device drivers. A For Each...Next loop
goes through each device and writes various data to the text file,
including the device name and description, and the driver version and
date.
Uninstalling a Device
When you remove a
Plug and Play device, the BIOS informs Windows 7 that the device is no
longer present. Windows 7, in turn, updates its device list in the
Registry, and the peripheral no longer appears in the Device Manager
display.
If you’re removing a
legacy device, however, you need to tell Device Manager that the device
no longer exists. To do that, follow these steps:
1. | Click the device in the Device Manager tree.
|
2. | Select
Action, Uninstall. (Alternatively, click Uninstall in the toolbar or
open the device’s properties sheet, display the Driver tab, and click
Uninstall.)
|
3. | When Windows 7 warns you that you’re about to remove the device, click OK. |